//#include "chp_reg.h"
#ifndef UINT8
typedef unsigned char 		UINT8;
#endif
#ifndef UCHAR
typedef unsigned char 		UCHAR;
#endif
#ifndef UINT16
typedef unsigned short int	UINT16;
#endif
#ifndef UINT32
typedef unsigned long int	UINT32;
#endif


#define IO_INW( io )		(UINT32) inpw( io )
#define IO_OUTWM( io, mask, val ) \
{\
	UINT32 temp;\
	(temp) =(((inpw(io) & (UINT32)(~(mask))) |((UINT32)((val) & (mask)))));\
	outpw( io, temp );\
}

#define PCONFC  0x01d20010
#define PDATC   0x01d20014
#define PUPC   0x01d20018


#define  PCONFG 0x01d20140
#define PDATG  0x01d20044
#define PUPG  0x01d20048
 
#define PCONFE  0x01d20028
#define PDATE   0x01d2002c
#define PUPE   0x01d20030



//GPE4 mercury power down 
#define MERCURY_POWER 0x10
#define MERCUEY_POWRER_MASK 0x300
#define MERCURY_POWER_VALUE 0x100
// GPE5 mercury reset	
#define MERCURY_RESET 0x20
#define MERCUEY_RESET_MASK 0xc00
#define MERCURY_RESET_VALUE 0x400
//vrover reset GPG6
#define VROVER_RESET 0x40
#define VROVER_RESET_MASK 0x3000
#define VROVER_RESET_VALUE 0x1000
//SCL GPE3
//#define SCL 0x08
#define SCL 0x200  //GPC9
#define SCL_CONFIG_MASK 0xC0
#define SCL_CONFIG_VALUE 0x40
//SDA GPG5
//#define SDA 0x20
#define SDA 0x20 //GPC5
#define SDA_CONFIG_MASK 0xC00
#define SDA_CONFIG_VALUE 0x400
#define configscl() CUST_IO_OUTWM(PCONFE,0xc0,0x40)

//#define set_scl(value) CUST_IO_OUTWM(PDATE,GPE3,value<<3)

#define configsda() CUST_IO_OUTWM(PCONFG,0xC00,0x400)
//#define set_sda(value) CUST_IO_OUTWM(PDATG,GPG5,value<<5)
#define VCHP_OUTH(io, val) (*((volatile UINT16 *) (io)) = ((UINT16) (val)))
#define VCHP_INH(io)       (*((volatile UINT16 *) (io)))
#define VCUST_IO_IN( io ,val)    \
do{\
    VCHP_OUTH(CHP_MODE_01_ADDR, (0x1000|(io)));\
    (val) = VCHP_INH(CHP_MODE_00_ADDR);\
}while(0)

#define VCUST_IO_OUT( io ,val)   \
do{\
    VCHP_OUTH(CHP_MODE_01_ADDR, (0x2000|(io)));\
    VCHP_OUTH(CHP_MODE_00_ADDR, (val));\
}while(0)


enum
{
	OP_VROVER_CONFIG,
	OP_VROVER_RESET,
	OP_MECURY_POWER,
	OP_MECURY_RESET,
	OP_VROVER_SET,
	OP_VROVER_READ,
	OP_VREVOR_WRITE,
	OP_I2C_SET,
	OP_VROVER_CHIP_INIT,
	OP_NORMAL_CHIP_INIT
};


typedef struct
{
	unsigned int op;
	union{
		struct{
			unsigned int address;
		}device;
		struct{
			unsigned int value;			
		}vrover_reset; 
		struct{
			unsigned int value;
		}mercury_power;
		struct{
			unsigned int value;
		}mercury_reset;
		struct{
			unsigned int value;
		}i2c_set;

		struct{
			unsigned int value;
		}vrover_read;

		struct{
			unsigned int address;
			unsigned int value;
		}vrover_write;
	}data;
}TST_VROVER_PARA_T;

int vrover_init_entry( void * context, void * para );
unsigned int i2c_read_data(unsigned int address);
void i2c_write_data(unsigned int address,unsigned int value);
void i2c_config(unsigned int value);